﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using PanGu;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.Web;
using MircoSoftTanslator;

namespace ChineseNLP
{

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Translator _translator;

        public MainWindow()
        {
            InitializeComponent();
            Segment.Init(System.IO.Path.GetFullPath(@".\PanGu.xml"));
            string clientID = "PatientInformationTranslate";
            string clientSecret = "PXNQ/w54tUo1UqNoaT5AYNIWErv2twGYM3LMu5FnoLc=";
            this._translator = new Translator(clientID, clientSecret, new TimeSpan(0, 1, 0));
        }

        private void btnProcess_Click(object sender, RoutedEventArgs e)
        {

            Segment segment = new Segment();
            ICollection<WordInfo> words = segment.DoSegment(txtOriginal.Text, true);
            rtbProcessed.Document.Blocks.Clear();
            Paragraph paragraph = new Paragraph();
            rtbProcessed.Document.Blocks.Add(paragraph);
            foreach (WordInfo word in words)
            {
                paragraph.Inlines.Add(new Run(word.Word) { Foreground = Brushes.Red });
                paragraph.Inlines.Add(new Run("/" + word.Pos + "/" + word.English + "/" + word.OriginalWordType + "/" + word.WordType + ","));

            }
        }

        private void btnTranslate_Click(object sender, RoutedEventArgs e)
        {

            string sourceText = txtOriginal.Text;
            string translationResult;
            //Keep appId parameter blank as we are sending access token in authorization header.
            translationResult = this._translator.Translate(sourceText, "zh-CHS", "en");
            rtbProcessed.Document.Blocks.Clear();
            Paragraph paragraph = new Paragraph();
            rtbProcessed.Document.Blocks.Add(paragraph);
            paragraph.Inlines.Add(new Run(translationResult));

        }

        private void btnReloadDict_Click(object sender, RoutedEventArgs e)
        {
            Segment.ReloadDictionary();
        }
    }
}
